package com.bnzjy.srb.core.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bnzjy.common.result.R;
import com.bnzjy.srb.core.pojo.entity.Borrower;
import com.bnzjy.srb.core.pojo.vo.BorrowerApprovalVO;
import com.bnzjy.srb.core.pojo.vo.BorrowerDetailVO;
import com.bnzjy.srb.core.service.BorrowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "借款人管理")
@RestController
@RequestMapping("/admin/core/borrower")
@Slf4j
public class AdminBorrowerController {
    
    @Resource
    BorrowerService borrowerService;
    
    /**
     * 获取借款人分页列表 进行分布展示
     * @param page
     * @param limit
     * @param keyword
     * @return
     */
    @ApiOperation("获取借款人分页列表")
    @GetMapping("/list/{page}/{limit}")
    public R listPage(@ApiParam(value = "当前页码", required = true)
                      @PathVariable Long page, @ApiParam(value = "每页记录数", required = true)
                      @PathVariable Long limit, @ApiParam(value = "查询关键字", required = false)
                      @RequestParam String keyword) {
        Page<Borrower> pageParam = new Page<>(page, limit);
        IPage<Borrower> pageModel = borrowerService.listPage(pageParam, keyword);
        
        return R.ok().data("pageModel", pageModel);
    }
    
    /**
     * 获取借款人信息，将借款人的信息在admin管理页面展示出来
     * @param id
     * @return
     */
    @ApiOperation("获取借款人信息")
    @GetMapping("/show/{id}")
    public R show(@ApiParam(value = "借款人id", required = true) @PathVariable Long id) {

        BorrowerDetailVO borrowerDetailVO = borrowerService.getBorrowerDetailVOById(id);
        return R.ok().data("borrowerDetailVO", borrowerDetailVO);
  
    }
    
    /**
     * 借款额度审批，进行审核
     * @param borrowerApprovalVO
     * @return
     */
    @ApiOperation("借款额度审批")
    @PostMapping("/approval")
    public R approval(@RequestBody BorrowerApprovalVO borrowerApprovalVO) {
        borrowerService.approval(borrowerApprovalVO);
        return R.ok().message("审批完成");
    }
}
